package net.cloudcodex.client.home.view.panel.character;

import java.util.Date;
import java.util.List;

import net.cloudcodex.client.home.view.HomeView.Message;
import net.cloudcodex.client.home.view.panel.NotificationIcone;
import net.cloudcodex.client.home.view.panel.StoryResponsPanel;
import net.cloudcodex.client.widgets.CharacterAvatar;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;

public class HomeCharacterPanel extends DockPanel {

	private CharacterAvatar characterAvatar = new CharacterAvatar();
	private HomeCharacterInfoPanel characterInfoPanel = new HomeCharacterInfoPanel();
	private NotificationIcone notifIcone = new NotificationIcone();
	private StoryResponsPanel characterStoryResponsPanel = new StoryResponsPanel();
	private Message message;
	private long characterId;

	public HomeCharacterPanel() {
		this.add(characterAvatar, DockPanel.WEST);
		HorizontalPanel centerPanel = new HorizontalPanel();
		centerPanel.add(characterInfoPanel);
		centerPanel.add(characterStoryResponsPanel);
		this.add(centerPanel, DockPanel.CENTER);
		this.setStyleName("characterPanel");

	}

	public void initComponent() {

		characterStoryResponsPanel.setMessage(message);
		characterInfoPanel.setMessage(message);
		characterInfoPanel.initPanel();
		characterStoryResponsPanel.initPanel();
		characterStoryResponsPanel.setStyleName("characterStoryResponsPanel");
		refreshNotifsIcone();
	}

	public void refreshNotifsIcone() {
		if (notifIcone.hasNotifs()) {
			this.add(notifIcone, DockPanel.EAST);
		} else {
			this.remove(notifIcone);
		}

	}
	public HasClickHandlers getCharacterAvatar() {
		return characterAvatar;
	}

	public void setMessage(Message message) {
		this.message = message;

	}

	public void addCharacter(long id, String icon, String name) {
		this.characterId = id ;
		characterAvatar.initComponent(icon, name, true);
		characterAvatar.setId(id);
	}

	public void addCampaignInfos(String name, String game, Date creationDate,
			String gameMasterNickname) {
		characterInfoPanel.setCampaignName(name);
		characterInfoPanel.setCampaignGM(gameMasterNickname);
		characterInfoPanel.setDateStartedCharacter(creationDate);
		characterInfoPanel.setGame(game);
	}

	public void addNotification(String message, Date date) {
		notifIcone.addNotification(message, date);
	}

	public void addStoryBoardResponse(List<String> charactersResponder) {
		characterStoryResponsPanel.addStoryBoardResponse(charactersResponder);
	}

	public HasClickHandlers getSeeMoreAnchor() {
		return characterStoryResponsPanel;
	}

	public Long getCharacterId() {
		return characterId;
	}

}